<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-10-24
 * Time: 16:47
 */

namespace App\Http\Controllers;


use App\Http\Controllers\Validator\OrderVali;
use App\Model\Order;
use App\Tool\Error;
use Illuminate\Http\Request;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class OrderController extends Controller
{

    /**
     * 获取订单列表
     */
    public function OrderList(Request $request)
    {
        $list = Order::orderList();
        if (!$list) {
            return $this->error(Error::NULL_DATA);
        }
        return $this->success('ok', $list);
    }

    /**二维码
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */

    public function GenerateTwoDimensionalCode(Request $request)
    {
        $params = $request->all();
        $vali = OrderVali::order($params);
        if(!$vali){
            return $this->error(Error::PARAM_MISSING);
        }
        $url = 'www.123456789.com';
        $str = $url.'?memberid='.$params['memberid'].'&zfbaccount='.$params['zfbaccount'].'&pay_amount='.$params['pay_amount'].'&orderid='.$params['orderid'].'&goods_title='.$params['zfbaccount'];
        if(!is_dir('../public/qrcodes')){
            mkdir('qrcodes');
        }
        QrCode::format('png')->size(500)->color(255,0,255)->generate($str, '../public/qrcodes/'.$params['zfbaccount'].time().'.png');
        $picUrl = '/qrcodes/'.$params['zfbaccount'].time().'.png';
        $status = Order::saveOrder($params, $picUrl);
        if (!$status) {
            return $this->error(Error::GENER_FAIL);
        }
        return $this->success('ok', '生成成功！');
    }


}